package itbour.onetouchshow.service;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;

import com.three.ConfigAppKey;
import com.three.ThirdConfigManager;
import com.umeng.analytics.MobclickAgent;
import com.umeng.analytics.game.UMGameAgent;

import java.io.File;

import itbour.onetouchshow.ExceptionCrashHander;

/**
 * 创建人：$ gyymz1993
 */

public class AppInitService extends IntentService {

    public static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
    public static String APP_ID = "wx5022d3c8ad81e74f";
    // public static OSSClient ossClient;
    private static Context mContext;
    String APP_SECRET = "db846ab731f65c89fe77c49ad3af5612";

    public AppInitService() {
        super("AppInitService");
    }

    public static void startService(Context context) {
        mContext = context;
        Intent intent = new Intent(context, AppInitService.class);
        context.startService(intent);

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        startService(new Intent(this, NetworkStateService.class));
        //iniAliyun();

        ConfigAppKey config = ConfigAppKey.instance().wxId(APP_ID).wxSecret(APP_SECRET);
        ThirdConfigManager.init(config);

        //友盟设置统计类型

        // 设置输出运行时日志
        //UMGameAgent.setDebugMode(true);
        UMGameAgent.init(this);
        // Deprecated UMGameAgent.setPlayerLevel("LV.01");
        UMGameAgent.setPlayerLevel(1);
        // UMGameAgent.setSessionContinueMillis(1000);
        // UMGameAgent.startWithConfigure(
        // new UMAnalyticsConfig(mContext, "4f83c5d852701564c0000011", "Umeng",
        // EScenarioType.E_UM_GAME));
        MobclickAgent.setScenarioType(mContext, MobclickAgent.EScenarioType.E_UM_GAME);
        // MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);

        ExceptionCrashHander.getInstance().init(mContext);
        // 获取上次的崩溃信息
        File crashFile = ExceptionCrashHander.getInstance().getCrashFile();
    }


//    private void iniAliyun() {
//        // L_.e("初始化阿里云");
//        String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
//        //阿里云OSS
//        OSSCredentialProvider credentialProvider = new OSSCustomSignerCredentialProvider() {
//
//            @Override
//            public String signContent(String s) {
//                HashMap<String, Object> stringStringHashMap = new HashMap<>();
//                stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
//                stringStringHashMap.put("strToSign", s);
//
//                final Semaphore semaph = new Semaphore(0);
//                L_.e("初始化阿里云" + AppNetConfig.GETOSSSIGN_V1_0);
//                HttpUtils.getInstance().executeGet(AppNetConfig.GETOSSSIGN_V1_0, stringStringHashMap, new EncryBeanCallBack() {
//                    @Override
//                    protected void onXError(String exception) {
//                        L_.e("初始化阿里云" + exception);
//                        semaph.release(1);
//
//                    }
//
//                    @Override
//                    protected void onSuccess(String response) {
//                        L_.i("response===" + response);
//
//                        OssSignBean ossSignBean = new Gson().fromJson(response, OssSignBean.class);
//                        App.accessKeyId = ossSignBean.getAccessKeyId();
//                        App.signature = ossSignBean.getSignature();
//                        semaph.release(1);
//                    }
//                });
//
//                try {
//                    semaph.acquire();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                if (App.accessKeyId == null || App.signature == null) {
//                    return null;
//                }
//                return "OSS " + App.accessKeyId + ":" + App.signature;
//            }
//        };
//        App.ossClient = new OSSClient(getApplicationContext(), endpoint, credentialProvider);
//    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }


}
